package tool

import (
	"gopkg.in/yaml.v2"
	"os"
)

type Hosts struct {
	Ports []int  `yaml:"ports"`
	Host  string `yaml:"host"`
}

type Schema struct {
	SchemaName string  `yaml:"schema"`
	Hosts      []Hosts `yaml:"hosts"`
}

type Probe struct {
	SchemaList []Schema `yaml:"probe"`
}

// 返回的是一个实例.不是引用. copy复制体.

func ReadYamlFile(configfile string) Probe {
	// var mp map[string]interface{}
	dataBytes, _ := os.ReadFile(configfile)
	//file, _ := os.Open("./config.yml")
	//defer file.Close()
	// fmt.Println("内容:", string(dataBytes))
	config := Probe{}
	yaml.Unmarshal(dataBytes, &config)
	return config
}
